﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YinfangWeb.BLL.Enum;
using YinfangWeb.BLL.Model;
using YinfangWeb.Model;

namespace YinfangWeb.DAL
{
    public partial class UserRightDAO
    {
        #region 获取 当前角色的所有权限
        /// <summary>
		/// 获取 当前角色的所有权限
		/// </summary>
		/// <returns>实体列表</returns>
        public List<ObjUserRightItem> GetListByRole(int roleid)
        {
            var sql = $"SELECT UserRightItem.UserRightItemID,UserRightItem.RightCode,UserRightItem.MenuItem FROM UserRight inner join UserRightItem on UserRight.UserRightItemID=UserRightItem.UserRightItemID where UserRoleID={roleid} and LimitedItem=0 order by UserRightItemID ";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                var q = conn.Query<ObjUserRightItem>(sql);
                return q.ToList();
            }
        }
        #endregion
        #region 删除 当前角色的所有权限
        /// <summary>
		/// 删除 当前角色的所有权限
		/// </summary>
		/// <returns>实体列表</returns>
        public bool DeleteByRole(int roleid)
        {
            var sql = $"delete FROM UserRight where UserRoleID={roleid}";
            using (var conn = ConnectionFactory.CreateConnection())
            {
                conn.Execute(sql);
                return true;
            }
        }
        #endregion
    }
}
